﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;

namespace WinFormsSprayProcessSCADASystem
{
    public partial class UserDeviceUnitControl : UIUserControl
    {
        public UserDeviceUnitControl()
        {
            InitializeComponent();
            this.Load += UserDeviceUnitControl_Load;
        }

        private void UserDeviceUnitControl_Load(object? sender, EventArgs e)
        {
            this.uiSwitch1.Active = this.isActive;
            this.uiLabel1.Text = this.labelText;
        }

        private string labelText = "默认名称";
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("label文本名称")]
        public string LabelText
        {
            get { return labelText; }
            set
            {
                labelText = value;
                this.uiLabel1.Text = labelText;
            }
        }

        private bool isActive = false;
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("是否打开")]
        public bool IsActive
        {
            get { return isActive; }
            set
            {
                isActive = value;
                this.uiSwitch1.Active = isActive;
            }
        }

        private string openVariableName = "";
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("打开状态的变量名称")]
        public string OpenVariableName
        {
            get { return openVariableName; }
            set
            {
                openVariableName = value;
            }
        }

        private string closeVariableName = "";
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("关闭状态的变量名称")]
        public string CloseVariableName
        {
            get { return closeVariableName; }
            set
            {
                closeVariableName = value;
            }
        }

        [Browsable(true)]
        [Category("自定义事件")]
        [Description("点击事件")]
        public event EventHandler? clickEvent;

        private void uiTableLayoutPanel1_Click(object sender, EventArgs e)
        {
            isActive = this.uiSwitch1.Active;
            clickEvent?.Invoke(this, e);
        }
    }
}
